﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Http;
using System.Net.Http.Headers;
using XclusiveClient.Classes;

namespace XclusiveClient
{
    public partial class AddAccount : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnCreateEmployee_Click(object sender, EventArgs e)
        {
            Employee temp = new Employee();
            temp.name = tbxname.Text;
            temp.company_name = Session["company_name"].ToString();
            temp.password = tbxpassword.Text;
            temp.account_type = "Basic";
            //End here for the storing..

            HttpClient client = new HttpClient();
            client.BaseAddress = new Uri("http://localhost:3676/");
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            var emp = new Employee()
            {
                name = temp.name,
                company_name = temp.company_name,
                password = temp.password,
                account_type = temp.account_type
            };

            HttpResponseMessage response = client.PostAsJsonAsync("api/Employee", emp).Result;
            if (response.IsSuccessStatusCode)
            {
                //Transfer to Success Page/Thankyou Page
            }
            else
            {
                lblStatus.Text = "Could not register for an account. Error code: " + response.StatusCode + ", Reason: " + response.ReasonPhrase.ToString() + "<br/>";
            }
        }
    }
}